﻿//配置文件

//请求地址
var ApiURL = 'http://localhost:83/';
//document.write('<script src="/Data/Data.js" type="text/javascript"></script>');

/**
 * 封装ajaxpost函数
 * @param {any} opt
 */
function ajaxpost(opt) {
    opt = opt || {};
    opt.url = opt.url || '';
    opt.data = opt.data || null;
    opt.success = opt.success || function () { };
    layui.use('layer', function () {
        var layer = layui.layer;

        $.ajax({
            url: ApiURL + opt.url,
            type: 'post',
            contentType: 'application/json',
            data: JSON.stringify(opt.data),
            success: function (data) {
                opt.success(data);
            },
            error: function (XMLHttpRequest) {
                var state = XMLHttpRequest.status;
                if (state === 401) {
                    layer.confirm('登陆凭证已过期，请重新登陆！', { icon: 2, title: '警告' }, function (index) {

                        window.open("/login.html");
                        localStorage.clear();//清空存储的值
                        sessionStorage.clear();
                        layer.close(index);
                    });
                }
                else {
                    location.href = "/error.html"
                }

            }
        })
    });   
    
}
/**
 * 封装ajaxget函数
 * @param {any} opt
 */
function ajaxget(opt) {
    opt = opt || {};
    opt.url = opt.url || '';
    opt.success = opt.success || function () { };
    layui.use('layer', function () {
        var layer = layui.layer;

        $.ajax({
            url: ApiURL + opt.url,
            type: 'get',
            contentType: 'application/json',
            success: function (data) {
                opt.success(data);
            },
            error: function (XMLHttpRequest) {
                var state = XMLHttpRequest.status;
                if (state === 401) {
                    layer.confirm('登陆凭证已过期，请重新登陆！', { icon: 2, title: '警告' }, function (index) {

                        window.open("/login.html");
                        localStorage.clear();//清空存储的值
                        sessionStorage.clear();
                        layer.close(index);
                    });
                }
                else {
                    location.href = "/error.html"
                }

            }
        })
    });   
}
